# misc.collections -- Useful collection items from elementary computer science courses
#
# V.A.Kelson, 20 February 2000

import copy
import UserList

class Stack:
    def __init__(self):
        """
        Creates an empty stack
        """
        self.list = [ ]
    def push(self,item):
        """
        Pushes an object onto the stack
        """
        self.list.append(item)
    def pop(self):
        """
        Pops the top item off the stack and returns it.
        """
        if len(self.list) == 0:
            return None
        else:
            return self.list.pop()
    def top(self):
		return self.list[0]
    def reset(self):
        """
        Removes all objects from the stack
        """
        self.list = [ ]

class Queue(UserList.UserList):
    def insert(self,item):
        """
        Appends the object onto the queue
        """
        self.data.append(item)
    def remove(self):
        """
        Returns the first item from the queue, and removes it from the queue
        """
        if len(self)>0:
            return self.data.pop(0)
        else:
            return None

class CircularList(UserList.UserList):
    """
    Implements a circular list that may be traversed by use of "MoveNext" and
    "MovePrevious" methods.  The "Item" method returns the currently pointed-to
    item.  Use the "remove" method to remove the current item.
    """
    def next(self):
        # Returns the next item in the list and places the current position there
        self.data.append(self.data.pop(0))
        return self.data[0]
    def previous(self):
        # Returns the previous item in the list and places the current position there
        self.data.insert(0,self.data.pop())
        return self.data[0]
    def item(self):
        return self.data[0]
    def insert(self,item):
        self.data.insert(0,data)
    def remove(self):
        if len(self) > 0:
            rv = self.data.pop(0)
            return rv
        else:
            return None
            
